<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>会员关系图调整 </title>

	
	
	
	 <!-- Bootstrap Core CSS -->
	<link href="__PUBLIC__/Theme2/css/bootstrap.min.css" rel='stylesheet' type='text/css' />
	<!-- Custom CSS -->
	<link href="__PUBLIC__/Theme2/css/style.css" rel='stylesheet' type='text/css' />
	<link href="__PUBLIC__/Theme2/css/font-awesome.css" rel="stylesheet"> 
	<!-- jQuery -->
	<script src="__PUBLIC__/Theme2/js/jquery.min.js"></script>

	<link href="__PUBLIC__/Theme2/css/custom.css" rel="stylesheet">
	<!-- Metis Menu Plugin JavaScript -->
	<script src="__PUBLIC__/Theme2/js/metisMenu.min.js"></script>
	<script src="__PUBLIC__/Theme2/js/custom.js"></script>
	<!-- Graph JavaScript -->
	<script src="__PUBLIC__/Theme2/js/d3.v3.js"></script>
	<script src="__PUBLIC__/Theme2/js/rickshaw.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="__PUBLIC__/Theme2/js/bootstrap.min.js"></script>

	
</head>

<body>

        <div class="col-md-12 graphs">
	   <div class="xs">
  	 <h3>会员关系图 </h3>
	 
	 
    <div class="panel panel-warning" data-widget="{&quot;draggable&quot;: &quot;false&quot;}" data-widget-static="">
				
				
				
				<style>
					.table-striped td{text-align:center;font-weight:bold;}
					
					.table td, .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{    padding: 15px 2px !important;}
					
				</style>
				<div class="panel-body no-padding">
					<table class="table table-striped"  cellpadding=0 cellspacing=0 >
						<tbody>
						
						
						
						<?php
							foreach($ceng_lists as $k=>$vitem)
							{
								$str = "<tr>";
								$str .= "<td  colspan=3>{$vitem[name]}({$vitem[leveldesc]})</td>";
								$str .= "</tr>";
								echo $str;
								echo opfunction($vitem);
								
								
							}
							
							function opfunction($item){
								$str .= shuchutop($item);
								if($item['level']>=4)
								{
									
									foreach($item['children'] as $c=>$cv)
									{
										if($cv['level']==3)
											$str_3 .= opfunction($cv);
										else
											$str .= opfunction($cv);
									}
								}
								if($cv['level']==3)
								{
									$str .= "<tr><td colspan=3><table style='width:100%'>";
									$str .= $str_3;
									$str .= "</tr></td></table>";
								}
								
								
								return $str;
							}
							
							
							
							function shuchutop($item,$self){
								//echo $item['name']."__".$item['level'].'__'.$item['leveldesc'].'__<br/>';
								if($item['level']==3)
								{
									foreach($item['children'] as $c=>$cv)
									{
										$str .=  shuchu($cv);
									}
								}
								else if($item['level']==4){
									//该有虚位
									$str = "<tr><td colspan='3'><table width=100%>";
									
									foreach($item['children'] as $c=>$cv)
									{
										$users = M("users");
										$teamCount = $users->where("tname={$cv[tname]} and standardlevel={$cv[level]} ")->count();
										$teamCount_array = $users->field("id,loginname,dianlevel")->where("tname={$cv[tname]} and dianlevel={$cv[level]} and standardlevel=0")->select();
										
										$teamCount_dian = count($teamCount_array);
										if($teamCount+$teamCount_dian==3){
										
											$str .= "<td>{$teamCount_array[0][loginname]}(虚位)</td>";
											$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
											$str .= "<td>{$teamCount_array[1][loginname]}(虚位)</td>";
											
										}
										elseif($teamCount+$teamCount_dian==2){
											$str .= "<td>{$teamCount_array[0][loginname]}(虚位)</td>";
											$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
											$str .= "<td>i+++{$cv[tname]}</td>";
										}
										else{
										
										//	echo $teamCount.'__'.$cv['name']."<br/>";
											if($teamCount==1)
											{
												$str .= "<td>i+++{$cv[tname]}</td>";
											}
											$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
											if($teamCount==1)
											{
												$str .= "<td>i+++{$cv[tname]}</td>";
											}
										}
									}
									
									$str .= "</tr></td></table>";
									
									
									
								}
								else if($item['level']==5){
									//该有虚位
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$cv)
									{
										if($cv['children']==1)
										{
											$str .= "<td>i+++{$cv[tname]}</td>";
										}
										$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
										if($cv['children']==1)
										{
											$str .= "<td>i+++{$cv[tname]}</td>";
										}
									}
									
									$str .= "</tr>";
									
									
									
								}
								else if($item['level']==2){
									
									//该有虚位
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$v)
									{
										$str .= shuchu01($v);
										
									}
									
									$str .= "</tr>";
								}
								else if($item['level']==1){
									$str = "<tr>";
									
									foreach($item['children'] as $c=>$cv)
									{
										$str .= "<td>{$cv[name]}({$cv[leveldesc]})</td>";
										
									}
									
									$str .= "</tr>";
								}
								
								return $str;
							}
		
							//第二级输出
							function shuchu($item){

								if($item['level']==2)
								{
									$i=0;
									$str = "<td id='td{$item[id]}' class='table-box'><table width=100% cellpadding=0 cellspacing=0><tr><td colspan=3>{$item[name]}({$item[leveldesc]})</td></tr><tr>";
									foreach($item['children'] as $k=>$v){
										
										$str .= shuchu01($v);
									}	
									$str .= "</tr>";
									
									$str .= "</table></td>";
								}
								
								return $str;
							}
							
							//第一级  输出
							function shuchu01($v)
							{
								$str .= "<td style='padding:15px 0 !important'><table width=100% cellpadding=0 cellspacing=0><tr><td style='    border-bottom: 1px solid red;'>{$v[name]}</td></tr>";
								foreach($v['children'] as $c=>$cv)
								{
									$str .= "<tr><td><input type='checkbox' name='ck' value='{$cv[id]}' class='cklevel0' id='{$cv[id]}' parval='{$cv[parent_id]}'/><lable for='{$cv[id]}'>{$cv[name]}</lable></td></tr>";// 3
									
								}
								
								if(3-$v['childrencount']>0)
								{
									$i=0;
								
									for($i=$v['childrencount'];$i<3;$i++)
									{
										$str .= "<tr><td>i++{$i}</td></tr>";
									}
								}
								
								
								$str .= "</table></td>";
								return $str;
							}
						?>
						
						</tbody>
					</table>
					
					 <form method="post" action="__APP__/User/tiaozhengAct" class="form-horizontal" id="form-admin-add" enctype="multipart/form-data">
					<div class="confirm-select" style="line-height:28px;text-align:center;display:none;" id="confimdiv">
						<input type="hidden" name="user1" id="user1" value="" />
						<input type="hidden" name="user2" id="user2" value="" />
						<input type="hidden" name="loginname" id="loginname" value="<{$loginname}>" />
						
						<div style="padding-bottom:2px;">是否将这2位用户调整位置？</div>
						<input type="submit" name="btnsub" value="是" />&nbsp;&nbsp;&nbsp;
						<input type="button" name="btnsub" value="否" onclick="cancelSelect()" />
					</div>
					</form>
				</div>
	</div>
	
   
	
  </div>
  <div class="copy_layout">
      <p>
	  </p>
  </div>
   </div>
   
   <script>
		$(".cklevel0").bind("change",function(){
			
			var parId= $(this).parents(".table-box").attr("id");

			if($(this).is(':checked')){
				$("#"+parId+" input[class='cklevel0']").attr("disabled","disabled"); 
			
				$(this).removeAttr("disabled");
				
				var checkcount = 0;
				var ck1,ck2;
				$(".table-box input[class='cklevel0']").each(function(){
					if($(this).is(':checked')){
						if(checkcount==0)
							ck1 = $(this).attr("id");
						else
							ck2 = $(this).attr("id");
							
						checkcount+=1;
					}
				})
				
				if(checkcount==2){
					$(".table-box input[class='cklevel0']").attr("disabled","disabled"); 
					$("#"+ck1).removeAttr("disabled");
					$("#"+ck2).removeAttr("disabled");
					
					$("#user1").val(ck1);
					$("#user2").val(ck2);
					
					$("#confimdiv").show();
				}
			}
			else{
				var seleid = null;
				$(".table-box input[class='cklevel0']").each(function(){
					if($(this).is(':checked')){
						alert('bb');
						seleid = $(this).parents(".table-box").attr("id");
					}
				})

				$(".table-box input[class='cklevel0']").removeAttr("disabled");
				$("#"+seleid+" input[class='cklevel0']").attr("disabled","disabled"); 
				$("#confimdiv").hide();
				
			}
			
			
			
		})
		
		function cancelSelect(){
			$(".table-box input[class='cklevel0']").removeAttr("disabled"); 
			$(".table-box input[class='cklevel0']").attr("checked",false);
			$("#confimdiv").hide();
		}
	
   </script>
    
</body>

</html>
